﻿using System;
using System.Diagnostics;
using System.IO;
using System.Windows;

using DbLayer;
using WordStat.Tasks;
using NHibernate_1;
using NHibernate;

namespace WordStat
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        internal FileContainer FileContainer { get; private set; }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //TestNHib();

            FileContainer = new FileContainer();
            FileContainer.LoadData(Directory.GetCurrentDirectory());

            TaskService.InitService(Directory.GetCurrentDirectory());
        }

        private void TestNHib()
        {
            Domain.Init();

            var session = Domain.CurrentSession;
            var tr = session.BeginTransaction();

            var book = new NHibDbLayer.Word() { WordText = "zag1" };

            long bookId = 0;

            try
            {
                session.Save(book);
                bookId = book.WordId;
            }
            catch (Exception e)
            {
            }

            tr.Commit();
            session.Flush();

            var book1 = session.Get<NHibDbLayer.Word>(bookId);

            Console.WriteLine(book1.WordText);

            if (book == book1) { Console.WriteLine("Yep!!!"); }

            Domain.Close();
        }
    }
}
